home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / utility / utilmisc / maestix.lha / Maestix / demos / Surround.s < prev   
Text File  |  1995-03-04  |  11KB  |  345 lines

  1. *****************************************************************
  2. *                                *
  3. *    maestix.library-Demo:    Surround            *
  4. *                                *
  5. *****************************************************************
  6. *
  7. *    Programmed by        Richard Körber
  8. *    Date            1995-02-01
  9. *
  10. *****************************************************************
  11. *  This demonstration shows how  to realise a real time effect  *
  12. *  using the maestix library.  It allocates the Maestro sound-    *
  13. *  card,  select the default input and sends the surround sig-    *
  14. *  nal to output.                        *
  15. *****************************************************************
  16.  
  17.         INCDIR    "include:"
  18.         INCLUDE    exec.i            ; Library call macros
  19.         INCLUDE    intuition.i
  20.         INCLUDE    graphics.i
  21.         INCLUDE    dos.i
  22.         INCLUDE    maestix.i
  23.         INCLUDE    libraries/maestix.i    ;Reference includes
  24.         INCLUDE    intuition/intuition.i
  25.         INCLUDE    dos/dostags.i
  26.         INCLUDE    exec/ports.i
  27.  
  28. BUFSIZE        EQU    24*1024            ;size of FIFO data block
  29.  
  30.         SECTION text,CODE
  31.  
  32. *---------------------------------------------------------------*
  33. *    == START OF PROGRAM ==                    *
  34. *                                *
  35. start    ;-- Open all libraries -----------------;
  36.         lea    maestname(PC),a1    ;maestix
  37.         moveq    #35,d0            ; V35+
  38.         exec    OpenLibrary        ; open
  39.         move.l    d0,maestbase        ; store base
  40.         beq    error1            ; not found!
  41.         lea    intuiname(PC),a1    ;intuition
  42.         moveq    #36,d0            ; V36+
  43.         exec    OpenLibrary        ; open
  44.         move.l    d0,intuibase        ; store base
  45.         beq    error2            ; not found!
  46.         lea    dosname(PC),a1        ;dos
  47.         moveq    #36,d0            ; V36+
  48.         exec    OpenLibrary        ; open
  49.         move.l    d0,dosbase        ; store base
  50.         beq    error3
  51.     ;-- Create buffer ----------------------;
  52.         move.l    #BUFSIZE*5,d0        ;size of five buffers
  53.         move.l    #$10001,d1        ;PUBLIC|CLEAR
  54.         exec    AllocMem
  55.         move.l    d0,buffer
  56.         beq    error4
  57.     ;-- Alloc signal bits ------------------;
  58.         sub.l    a1,a1            ;get task ptr
  59.         exec    FindTask
  60.         move.l    d0,maintask
  61.         moveq    #-1,d0            ;Allocate a 2nd signal bit
  62.         exec    AllocSignal
  63.         move.b    d0,donesigbit
  64.         cmp.b    #-1,d0            ;no signals free?
  65.         beq.w    error5
  66.     ;-- Open handle window -----------------;
  67.         sub.l    a0,a0            ;no newwindow struct
  68.         lea    windowtags(PC),a1    ; but loads of tags
  69.         intui    OpenWindowTagList
  70.         move.l    d0,window
  71.         beq    error6
  72.     ;-- Launch surround task ---------------;
  73.         move.l    #tasktags,d1        ;Tags for new task
  74.         dos    CreateNewProc        ;create new process
  75.         tst.l    d0            ;got the task?
  76.         beq    error7
  77.         moveq    #0,d0            ;wait 'till 2nd task setup'd
  78.         move.b    donesigbit(PC),d1    ; signal
  79.         bset    d1,d0
  80.         exec    Wait            ;wait for this event
  81.     ;-- Wait for reply (main loop) ---------;
  82. .mainloop    move.l    window(PC),a0        ;window message?
  83.         move.l    wd_UserPort(a0),a0    ; ^message port
  84.         exec    WaitPort
  85. .nextmsg    move.l    window(PC),a0        ;window message?
  86.         move.l    wd_UserPort(a0),a0    ; ^message port
  87.         exec    GetMsg            ; try to get it...
  88.         tst.l    d0            ; got one?
  89.         beq.b    .mainloop        ; nope: wait for next msg
  90.     ;---- got a window event ---------------;
  91.         move.l    d0,a0            ;^IDCMP-message -> a0
  92.         cmp.l    #IDCMP_CLOSEWINDOW,im_Class(a0) ;close window?
  93.         bne.b    .nextmsg        ; no -> continue being idle ;)
  94.     ;-- Exit program -----------------------;
  95. exit        move.l    surrtask(PC),a1        ;Shut surround task
  96.         moveq    #0,d0
  97.         move.b    surrsigbit(PC),d1
  98.         bset    d1,d0
  99.         exec    Signal            ; signals the exit
  100.         moveq    #0,d0            ;wait 'till 2nd task exited
  101.         move.b    donesigbit(PC),d1    ; signal
  102.         bset    d1,d0
  103.         exec    Wait            ;wait for this event
  104. error7        move.l    window(PC),a0        ;Close output window
  105.         intui    CloseWindow
  106. error6        move.b    donesigbit(PC),d0
  107.         exec    FreeSignal
  108. error5        move.l    buffer(PC),a1        ;^Buffer
  109.         move.l    #BUFSIZE*5,d0
  110.         exec    FreeMem
  111. error4        move.l    dosbase(PC),a1        ;close dos library
  112.         exec    CloseLibrary
  113. error3        move.l    intuibase(PC),a1    ;close intuition library
  114.         exec    CloseLibrary
  115. error2        move.l    maestbase(PC),a1    ;close maestix library
  116.         exec    CloseLibrary
  117. error1        moveq    #0,d0            ;Reply 0
  118.         rts                ;back to CLI
  119.  
  120. *---------------------------------------------------------------*
  121. *    == SURROUND PROCESS ==                    *
  122. *                                *
  123. SurroundProc
  124.     ;-- Get exiting signal -----------------;
  125.         sub.l    a1,a1            ;Get task structure
  126.         exec    FindTask
  127.         move.l    d0,surrtask
  128.         moveq    #-1,d0            ;get sig bit
  129.         exec    AllocSignal
  130.         move.b    d0,surrsigbit
  131.         cmp.b    #-1,d0            ;got no bit
  132.         beq    .error1
  133.         move.l    maintask(PC),a1        ;task is done
  134.         moveq    #0,d0
  135.         move.b    donesigbit(PC),d1
  136.         bset    d1,d0
  137.         exec    Signal            ; signals the exit
  138.     ;-- Allocate Maestro -------------------;
  139.         sub.l    a0,a0            ;no tags
  140.         maest    AllocMaestro
  141.         move.l    d0,maestro        ;^Maestro base
  142.         beq    .error2
  143.     ;-- Set Modus --------------------------;
  144.         move.l    maestro(PC),a0        ;^Maestro base
  145.         lea    modustags(PC),a1    ;^Modus tags
  146.         maest    SetMaestro        ;set it now
  147.     ;-- Read Status ------------------------;
  148.         move.l    maestro(PC),a0        ;^Maestro base
  149.         move.l    #MSTAT_Signal,d0    ;is input signal ok?
  150.         maest    GetStatus        ;get the card status
  151.         tst.l    d0
  152.         beq    .error3
  153.     ;-- Create Messageports ----------------;
  154.         exec    CreateMsgPort        ;create a messageport
  155.         move.l    d0,rport        ; as receive port
  156.         beq    .error3
  157.         exec    CreateMsgPort        ;create a messageport
  158.         move.l    d0,tport        ; as transmit port
  159.         beq    .error4
  160.     ;-- Init messages ----------------------;
  161.         move.l    rport(PC),d1        ;^Receive Reply Port
  162.         move.l    tport(PC),d2        ;^Transmit Reply Port
  163.         lea    msg1(PC),a0        ;^1st Message
  164.         lea    msg2(PC),a1
  165.         lea    msg3(PC),a2
  166.         lea    msg4(PC),a3
  167.         lea    msg5(PC),a4
  168.         move.l    buffer(PC),d0        ;get buffer ptr
  169.         move.l    d0,(dmn_BufPtr,a0)    ; set buffer 1
  170.         add.l    #BUFSIZE,d0
  171.         move.l    d0,(dmn_BufPtr,a1)    ; set buffer 2
  172.         add.l    #BUFSIZE,d0
  173.         move.l    d0,(dmn_BufPtr,a2)    ; set buffer 3
  174.         add.l    #BUFSIZE,d0
  175.         move.l    d0,(dmn_BufPtr,a3)    ; set buffer 4
  176.         add.l    #BUFSIZE,d0
  177.         move.l    d0,(dmn_BufPtr,a4)    ; set buffer 5
  178.         move.l    #BUFSIZE,(dmn_BufLen,a0) ;Set buffer length
  179.         move.l    #BUFSIZE,(dmn_BufLen,a1)
  180.         move.l    #BUFSIZE,(dmn_BufLen,a2)
  181.         move.l    #BUFSIZE,(dmn_BufLen,a3)
  182.         move.l    #BUFSIZE,(dmn_BufLen,a4)
  183.         move.l    d1,(MN_REPLYPORT,a0)    ;Set Reply-Port
  184.         move.l    d1,(MN_REPLYPORT,a1)
  185.         move.l    d2,(MN_REPLYPORT,a2)
  186.         move.l    d2,(MN_REPLYPORT,a3)
  187.         move.l    d2,(MN_REPLYPORT,a4)
  188.         move    #dmn_SIZEOF,(MN_LENGTH,a0) ;Set msg length
  189.         move    #dmn_SIZEOF,(MN_LENGTH,a1)
  190.         move    #dmn_SIZEOF,(MN_LENGTH,a2)
  191.         move    #dmn_SIZEOF,(MN_LENGTH,a3)
  192.         move    #dmn_SIZEOF,(MN_LENGTH,a4)
  193.     ;-- Start receive process --------------;
  194.         move.l    maestro(PC),a0        ;transmit msg to library
  195.         lea    msg1(PC),a1
  196.         maest    ReceiveData        ; the 1st (starts receiver!)
  197.         move.l    maestro(PC),a0
  198.         lea    msg2(PC),a1
  199.         maest    ReceiveData        ; and the 2nd
  200.         move.l    maestro(PC),a0
  201.         lea    msg3(PC),a1
  202.         maest    TransmitData        ; and the 3rd
  203.         move.l    maestro(PC),a0
  204.         lea    msg4(PC),a1
  205.         maest    TransmitData        ; and the 4th
  206.         move.l    maestro(PC),a0
  207.         lea    msg5(PC),a1
  208.         maest    TransmitData        ; and the 5th
  209.     ;-- wait for messages ------------------;
  210. .mainloop    move.l    tport(PC),a0        ;maestix message?
  211.         exec    GetMsg            ; try to get it...
  212.         tst.l    d0            ; got one?
  213.         bne.b    .gottransmit        ; then evaluate it
  214.         move.l    rport(PC),a0        ;receive message?
  215.         exec    GetMsg
  216.         tst.l    d0
  217.         bne.b    .gotreceive
  218.         moveq    #0,d0            ;create wait mask
  219.         move.b    surrsigbit(PC),d1    ; signal for exiting
  220.         bset    d1,d0
  221.         move.l    rport(PC),a0        ; second, from receive port
  222.         move.b    MP_SIGBIT(a0),d1    ; sig bit
  223.         bset    d1,d0            ; set this bit
  224.         move.l    tport(PC),a0        ; last, from transmit port
  225.         move.b    MP_SIGBIT(a0),d1
  226.         bset    d1,d0
  227.         exec    Wait            ;wait for these events
  228.         move.b    surrsigbit(PC),d1    ; exit forced?
  229.         btst    d1,d0            ; test this bit
  230.         beq.b    .mainloop        ;not wanted -> main loop
  231.         bra.b    .exit            ; wanted -> leave
  232.     ;---- got a transmitter event ----------;
  233. .gottransmit    move.l    maestro(PC),a0        ;Re-send message
  234.         move.l    d0,a1
  235.         move.l    rport(PC),(MN_REPLYPORT,a1) ;Set Reply-Port
  236.         maest    ReceiveData        ; to maestix library
  237.         bra.b    .mainloop
  238.     ;---- got a receive event --------------;
  239. .gotreceive    bsr    surround        ;do the surround
  240.         bra.b    .mainloop        ;and try again
  241.     ;-- Leave task -------------------------;
  242. .exit        move.l    maestro(PC),a0        ;Flush all messages
  243.         maest    FlushTransmit
  244.         move.l    maestro(PC),a0
  245.         maest    FlushReceive
  246.         move.l    tport(PC),a0        ;delete transmit port
  247.         exec    DeleteMsgPort
  248. .error4        move.l    rport(PC),a0        ;delete receive port
  249.         exec    DeleteMsgPort
  250. .error3        move.l    maestro(PC),a0        ;Set maestro free
  251.         maest    FreeMaestro
  252. .error2        move.l    maintask(PC),a1        ;task is done
  253.         moveq    #0,d0
  254.         move.b    donesigbit(PC),d1
  255.         bset    d1,d0
  256.         exec    Signal            ; signals the exit
  257. .error1        rts                ;done (freed by DOS)
  258.  
  259. *-------------------------------------------------------*
  260. *  surround    calculate surround data            *
  261. *    -» D0.l    ^Maestro Msg                *
  262. *                            *
  263. surround    move.l    d0,a1            ;get ptr
  264.     ;-- Get pointers -----------------------;
  265.         move.l    dmn_BufPtr(a1),a0    ;a0: ^received data
  266.         move.l    dmn_BufLen(a1),d0
  267.         lea    (a0,d0.l),a2        ;a2: ^end of buffer
  268.     ;-- Surrounding ------------------------;
  269. .loop        move    (a0),d0            ;left word
  270.         ext.l    d0
  271.         move    2(a0),d1        ;right word
  272.         ext.l    d1
  273.         sub.l    d1,d0            ;difference
  274.         asr.l    #1,d0
  275.         move    d0,(a0)+
  276.         move    d0,(a0)+
  277.         cmp.l    a2,a0            ;end reached?
  278.         blo.b    .loop
  279.     ;-- Send buffer to transmitter ---------;
  280.         move.l    maestro(PC),a0        ;Send message
  281.         move.l    tport(PC),(MN_REPLYPORT,a1) ;Set Reply-Port
  282.         maest    TransmitData        ; to transmitter
  283.     ;-- Done -------------------------------;
  284.         rts
  285.  
  286. *---------------------------------------------------------------*
  287. *    == DATA SECTION ==                    *
  288. *                                *
  289. maintask    dc.l    0            ;^Main task
  290. surrtask    dc.l    0            ;^Surround task
  291. surrsigbit    dc.b    0            ;Surround task signal bit
  292. donesigbit    dc.b    0            ;Main task done sigbit
  293.         even
  294. maestbase    dc.l    0            ;^Maestix Lib Base
  295. intuibase    dc.l    0            ;^Intuition Lib Base
  296. dosbase        dc.l    0            ;^DOS Lib Base
  297. maestro        dc.l    0            ;^Maestro Base
  298. rport        dc.l    0            ;^Receive MsgPort
  299. tport        dc.l    0            ;^Transmit MsgPort
  300. buffer        dc.l    0            ;^Data buffer
  301. window        dc.l    0            ;^Window structure
  302. msg1        ds.b    dmn_SIZEOF        ;^first message
  303. msg2        ds.b    dmn_SIZEOF        ;^second message
  304. msg3        ds.b    dmn_SIZEOF        ;^third message
  305. msg4        ds.b    dmn_SIZEOF        ;^fourth message
  306. msg5        ds.b    dmn_SIZEOF        ;^fifth message
  307.  
  308. modustags    dc.l    MTAG_Input,INPUT_STD    ;use standard input
  309.         dc.l    MTAG_Output,OUTPUT_FIFO
  310.         dc.l    MTAG_CopyProh,CPROH_OFF
  311.         dc.l    MTAG_Emphasis,EMPH_OFF
  312.         dc.l    MTAG_Source,SRC_INPUT
  313.         dc.l    MTAG_Rate,RATE_INPUT
  314.         dc.l    TAG_DONE
  315.  
  316. tasktags    dc.l    NP_Entry,SurroundProc    ;<- New process' tags
  317.         dc.l    NP_Priority,30
  318.         dc.l    NP_Name,.name
  319.         dc.l    TAG_DONE
  320. .name        dc.b    "Maestix surround process",0
  321.         even
  322.  
  323. windowtags    dc.l    WA_IDCMP,IDCMP_CLOSEWINDOW ;<- New window's tags
  324.         dc.l    WA_Title,.title
  325.         dc.l    WA_InnerWidth,150
  326.         dc.l    WA_InnerHeight,0
  327.         dc.l    WA_DragBar,-1
  328.         dc.l    WA_DepthGadget,-1
  329.         dc.l    WA_CloseGadget,-1
  330.         dc.l    WA_Activate,-1
  331.         dc.l    WA_RMBTrap,-1
  332.         dc.l    TAG_DONE
  333. .title        dc.b    "Surround generator",0
  334.         even
  335.  
  336. maestname    dc.b    "maestix.library",0    ;Maestix name
  337. intuiname    dc.b    "intuition.library",0    ;Intuition name
  338. dosname        dc.b    "dos.library",0        ;DOS name
  339.         even
  340.  
  341. *---------------------------------------------------------------*
  342. *    == END ==                        *
  343. *                                *
  344.         END
  345.